March 29th, 2022
That being said no one wants to be frustrated while coding hence no one wants bugs in their codes.
Developers, often do not get it all right ("code-wise") at first try; consequently, the software development cycle involves debugging, refactoring, upgrading, and many other enhancement operations.
In addition, developers know that many a time we all have to deal with bugs in our code. Hence debugging is an invaluable skill in a developer's repertoire. And to be successful at debugging, we need a good understanding of error messages.
Error codes or messages are the ways computers inform us that there are bugs in our codes, and sometimes it tells us where they are.
The paradox is that error codes; although are very helpful, they are not plain English and can be very confusing and cryptic
Below are error codes from a crashed app on Heroku.
2019-10-11T11:27:28.019054+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=realtylabapp.herokuapp.com request_id=74165d9f-db2a-46bd-ab9c-1a01403bd00f fwd="129.205.113.108" dyno= connect= service= status=503 bytes= protocol=https
2019-10-11T11:27:29.919409+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=realtylabapp.herokuapp.com request_id=fa48efa2-4ddf-41e6-a633-a62cb02314bd fwd="129.205.113.108" dyno= connect= service= status=503 bytes= protocol=https
Heroku uses a unique alphanumeric error code combo to communicate to the developer the kind of error that was found in their code.
This alphanumeric error code ranges from:
H10
to H99
R10
to R99
L10
to L15
Get a detailed list here: Complete Heroku Error Codes
This article is focused on the Heroku H10-App crashed
error code which is thrown when an application crashes on Heroku. This is as much as it goes. It does not help us with the reason our app crashed and that's where this article comes in. Below are some causes of this error and I guarantee you that some of them would surprise you greatly!
Bug in Procfile A very interesting discovery for me. A bug in your Procfile can crash your app. If your Procfile is pointing to the wrong server file. e.g If your server is in server.js and your Procfile points to app.js this would definitely crash your app and Heroku would greet you with the H10-App crashed error code message. Secondly, a buggy Procfile can also come in the form of wrong spacing. e.g Wrong: web : node index.js Correct web: node index.js
Setting a PORT as a Heroku environment variable
This would surely crash your app. Heroku automatically sets a Port that can be accessed via process.env.PORT
. Setting a port yourself would crash your app. Surprisingly, the command heroku config
does not display the preset Heroku port so one might be tempted to set another port as an environment variable.
To see all the preset Heroku environment variables, use the command heroku run printenv
.
Missing Required Environment Variable while setting a port would cause this error because Heroku already sets a port internally, failing to set any required environment variable (e.g your database), would prompt Heroku to greet you with this error.
Missing Required Scripts
This error is thrown in a Node.js environment if you forget to set a start script
. Heroku uses this script to start your app so if it is missing, it would throw an H10-App crashed
error code message.
This can be solved by setting a start script
in the package.json
. e.g
"scripts": {
"start": "node index.js"
}
Final Thoughts
If none of the above solved your problem, you can make a last-ditch attempt by updating all your packages. If this doesn't help and you are in a Node.js
environment, your last resort would be setting a node version
in the engine section of your package.json
file.
{
"name": "myapp",
"description": "a really cool app",
"version": "1.0.0",
"engines": {
"node": "12.11.1"
}
}
The Unthinkable
Lastly, if your bug defiles all solution, and by this time you are grasping at straws; I leave you in the able hands of heroku restart
.